package cn.jr.service.impl;

import cn.jr.dao.IOrderDao;
import cn.jr.dao.impl.OrderDaoImpl;
import cn.jr.pojo.Order;
import cn.jr.service.IOrderService;

import java.util.ArrayList;

public class OrderServiceImpl implements IOrderService {
    IOrderDao iod=new OrderDaoImpl();
    @Override
    public boolean addOrder(double priceAll, double priceAllSJ) {
        return iod.insertOrder(priceAll,priceAllSJ)>0?true:false;
    }

    @Override
    public String selectOrder(String orderNumber) {
        return iod.selectOrder(orderNumber);
    }

    @Override
    public double queryOrderByTime(String startTime, String endTime) {
        /**
         * 根据时间段查询订单金额总和
         * @param startTime 开始时间
         * @param endTime 结束时间
         * @return 订单金额总和
         */
        ArrayList<Order> list= iod.selectOrderByTime(startTime,endTime);
        double sum=0;
        for(Order order:list){
            sum+=order.getOrderRealyPrice();
        }
        return sum;
    }

    @Override
    public String selectOrderByOrderId(String orderId) {
        return iod.selectOrderByOrderId(orderId);
    }
}
